<?php
 class CustomerVideos extends CI_Model{
    function __construct(){
        parent::__construct();
    }
    
    /**
     * get option video customer
     * @author tien.nguyen
     */
    public function getCustomerVideo($customerId){
        $this->db->select('customer_videos.VideoId');
        $this->db->from('customer_videos');
        $this->db->where('customer_videos.CustomerId', $customerId);
        $query = $this->db->get();
        $list = $query->result();
        $res = array();
        
        foreach($list as $item){
            array_push($res, $item->VideoId);
        }    
        return $res;
    }
    
    /**
     * add customer video
     * @author tien.nguyen
     */
    public function add($data){
        $data = $this->_convertData($data);
        return $this->db->insert('customer_videos', $data);
    }
    
    /**
     * delete all customer video
     * @author tien.nguyen
     */
    public function delete($customerId){
        return $this->db->delete('customer_videos', array('CustomerId' => $customerId)); 
    }
    
    private function _convertData($data){
        $res = array();
        $arr = array('CustomerVideoId', 'CustomerId', 'VideoId', 'CreatedDate');
        foreach($arr as $item){
            if(isset($data[$item])){
                $res[$item] = $data[$item];
            }
        } 
        return $res;
    }
 }
?>